package com.wangyadong.hobby.common.service.impl;

import com.wangyadong.hobby.common.service.WuserInfoServices;
import com.wangyadong.hobby.front.model.WuserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wangyadong.hobby.common.dao.MyBatisDao;
import com.wangyadong.hobby.common.utils.Pagination;

import java.util.List;

@Service
public class WuserInfoServicesImpl implements WuserInfoServices {

    @Autowired
    private MyBatisDao myBatisDao;

    @Override
    public WuserInfo getWuserInfoByUserName(String userName) {
        return myBatisDao.get("w_userinfo.selectByUserName", userName);
    }

    /**
     * 添加wuserInfo
     */
    @Override
    public WuserInfo addWuserInfo(WuserInfo wuserInfo) {
        myBatisDao.insert("w_userinfo.insertSelective", wuserInfo);
        return wuserInfo;
    }

    /**
     * 修改wuserInfo
     */
    @Override
    public WuserInfo updateWuserInfo(WuserInfo wuserInfo) {
        myBatisDao.update("w_userinfo.updateByPrimaryKey", wuserInfo);
        return wuserInfo;
    }

    /**
     * 根据ID加载一条wuserInfo信息
     *
     * @param addressId wuserInfoID
     */
    @Override
    public WuserInfo getWuserInfoById(Long wuserInfoId) {
        return myBatisDao.get("w_userinfo.selectByPrimaryKey", wuserInfoId);
    }


    @Override
    public List<WuserInfo> getWuserInfoList(int params, int pageNo, int pageSize) {
        Integer count = myBatisDao.count("w_userinfo.selectByPrimaryKeyPaging", params);
        if (count <= 0) {
            return null;
        }
        Pagination<WuserInfo> pagination = new Pagination<WuserInfo>();
        pagination.setCurrentPage(pageNo);
        pagination.setPageSize(pageSize);
        List<WuserInfo> wuserInfoList = myBatisDao.getListForPaging("w_userinfo.selectByPrimaryKeyPaging",
                params, pageNo, pageSize);
        pagination.setRows(wuserInfoList);
        //分页查询
        pagination.setTotal(count);
        return wuserInfoList;
    }

    @Override
    public WuserInfo getWuserInfoByEmail(String emai) {
        return myBatisDao.get("w_userinfo.selectByEmail", emai);
    }
}
